package com.zzyl.nursing.controller;

import java.util.List;
import com.zzyl.nursing.dto.DoNursingTaskDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.NursingTask;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import com.zzyl.nursing.service.INursingTaskService;

/**
 * 护理任务Controller
 *
 * @author zzyl
 * @date 2025-10-31
 */
@RestController
@RequestMapping("/nursing/nursingTask")
@Api(tags = "护理任务相关接口")
public class NursingTaskController extends BaseController
{
    @Autowired
    private INursingTaskService nursingTaskService;

    /**
     * 分页查询护理任务列表
     */
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam Map<String, Object> params) {
        startPage();
        List<NursingTask> list = nursingTaskService.selectNursingTaskList(params);
        return getDataTable(list);
    }

    /**
     * 获取护理任务详情
     */
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Integer id) {
        return success(nursingTaskService.getDetailById(id));
    }

    /**
     * 取消任务
     */
    @PutMapping("/cancel")
    public AjaxResult cancel(@RequestBody Map<String, Object> body) {
        Long taskId = Long.valueOf(body.get("taskId").toString());
        String reason = (String) body.get("reason");
        nursingTaskService.cancelTask(taskId, reason, getUsername());
        return success("操作成功");
    }

    /**
     * 任务执行
     * @param dto
     * @return
     */
    @PutMapping("/do")
    @ApiOperation("任务执行")
    public AjaxResult doNursingTask(@RequestBody DoNursingTaskDto dto) {
        nursingTaskService.doNursingTask(dto);
        return success();
    }

    /**
     * 任务改期
     * @param dto
     * @return
     */
    @PutMapping("/updateTime")
    @ApiOperation("任务改期")
    public AjaxResult updateTimeNursingTask(@RequestBody DoNursingTaskDto dto) {
        nursingTaskService.updateTimeNursingTask(dto);
        return success();
    }
}